<template>
  <article class="page">
    <headerbar>评价详情</headerbar>
    <section class="frame-content-sub no-bg">

      <section class="inner-content pdv-9 pdh-4">


          <appraisePie :charData="list" style="height:80vh;" :id="'c2'"></appraisePie>


      </section>

    </section>
  </article>
</template>

<script>
  import _ from 'lodash'
  import appraisePie from '../../../components/common/appraisePie.vue'
  export default {
    components: {appraisePie},
    name: 'appraiseManage',
    data () {
      return {
        routeName: '1',
        pageIndex: 1,
        pageSize: 10,
        list: [],
        options: {
          pullUpLoad: true,
          scrollbar: false
        }
      }
    },
    created () {
      console.log(this.$route.query)
      this.trainingplanpjList()
    },
    methods: {
      clickNav (index) {
        this.routeName = index
        this.pageIndex = 1
        this.list = []
        this.trainingplanpjList(index)
      },
      trainingplanpjList (index) {
        // 类型(1学员对培训机构的评价 2学员对主办单位的评价 3学员对讲师及讲授课程的评价 4培训机构对学员的评价 5主办单位对学员的评价)
        index = index || '1'
        let query = this.$route.query
        let params = {
          "type": query.type,
          "limit": this.pageSize,
          "page": this.pageIndex
        }
        params = _.extend(this.findPropertyValueWithKey(query, 'id'), params)
        return this.fetchService.trainingplanpjList(params).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message || '获取数据失败')
          }
          this.list = this.makePieData(res.data)
          return res
        })
      },
      makePieData (data) {
        let list = []
        data.forEach(v => {
          let name = v.evaluationCriterionPfxm || v.evaluationCriterionXmbm
          if (!name) {
            return
          }
          list.push({
            value: v.score,
            name: name + '\n\n' + `(${v.score})`
          })
        })
        return list
      },
      findPropertyValueWithKey (data, key) {
        for (let i in data) {
          if (i.toLowerCase().indexOf(key) !== -1) {
            let ret = {}
            ret[i] = data[i]
            return ret
          }
        }
      }
    }
  }
</script>

<style scoped>

</style>
